package com.Visitor;

public class Client {
    public static void main(String[] args) {
        IProduct b1 = new Book();
        IProduct b2 = new Book();
        IProduct a1 = new Apple();
        AVisitor visitor = new AVisitor() {
            public void visit(Apple apple){
                System.out.println("顾客" + name + "选苹果");
            }
            public void visit(Book book){
                System.out.println("顾客" + name + "买书");
            }
        };

        BuyBasket basket = new BuyBasket();
        basket.addProduct(b1);
        basket.addProduct(b2);
        basket.addProduct(a1);

        visitor.setName("张三");
        basket.accept(visitor);
    }
}
